/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-05-13     lyh       the first version
 * 此文件是基于RTT的GPIO操作示例
 */

#include <rtthread.h>
#include <rtdevice.h>

#define GPIO_PE0 64

/*
 * 定义线程句柄、线程堆栈大小、时间片参数、线程优先级
 */
#define THREAD_PRIORITY         25
#define THREAD_STACK_SIZE       512
#define THREAD_TIMESLICE        5
static rt_thread_t gpioThread = RT_NULL;

static void rttGpioDemoEntry(void* params)
{
    //1.初始化GPIO接口
    rt_pin_mode(GPIO_PE0, PIN_MODE_OUTPUT);

    unsigned int count = 1;
    int pinState = 2;
    while (count < 10)
    {
        //2.设置输出低电平状态
        rt_pin_write(GPIO_PE0, PIN_LOW);
        rt_thread_mdelay(500);
        rt_kprintf("gpio set  low \n");
        //2.设置输出高电平状态
        rt_pin_write(GPIO_PE0, PIN_HIGH);
        rt_thread_mdelay(500);
        rt_kprintf("gpio set  high \n");
        count++;
    }
}

int rttGpioDemo(void)
{

    gpioThread = rt_thread_create("gpioDemoThread", rttGpioDemoEntry,
    RT_NULL,
    THREAD_STACK_SIZE,
    THREAD_PRIORITY,
    THREAD_TIMESLICE);

    if (gpioThread != RT_NULL)
    {
        rt_thread_startup(gpioThread);
    }

    return 0;

}

MSH_CMD_EXPORT(rttGpioDemo, rttGpioDemo)
